const app = getApp();
const Controller = require('../controllers/controllers.js').controller;

Page({
  data: {
    hasMobile: false, //没有手机号
    isuser:false
  },
  onShow(option) {
    if(wx.getStorageSync('role')){
      if(wx.getStorageSync('role')==2){
        this.setData({
          isuser:false
        })
      }else{
        this.setData({
          isuser:true
        })
      }
    }else{
      this.setData({
        isuser:true
      })
    }
  },
  goagree(){
    wx.navigateTo({
      url: "/pages/Login/agree"
    })
  },
  bindgetuserinfoBtn(e) {
    var that=this;
    wx.getUserProfile({
      desc: '用于完善会员资料', // 声明获取用户个人信息后的用途，后续会展示在弹窗中，请谨慎填写
      success: (res) => {
        if(res.userInfo){
          wx.setStorageSync('wxuserInfo', res.userInfo)
          app.updateUserInfo(res).then(res => {
            that.setData({
              hasMobile:true
            })
          })
        }
      },
      fail:(res)=>{
        console.log(res)
      }
    })
  },
  // 手机授权
  bindgetphonenumber(e) {
    console.log(e)
    if(e.detail && e.detail.errMsg!='getPhoneNumber:fail user deny'){
      app.updatePhoneNumber(e.detail).then(res => {
        var logintoken=wx.getStorageSync('logintokenlinshi')
        wx.setStorageSync('logintoken',logintoken)
        if(this.data.isuser){
          wx.showToast({
            title: '登录成功！',
            icon: 'success',
            duration: 2000
          })
          
          setTimeout(res => {
            wx.navigateBack({ //返回
              delta: 2
            })
          },2000)
        }else{
          wx.reLaunch({
            url: "/pages/Login/cert"
          })
        }
      })
    }
  },
  cancel(){
    wx.navigateBack({ //返回
      delta: 1
    })
  },

})